/**
 * 渠道商
 * */


(function () {
})();


//列表
function getList(){
    $.ajax({
        type: apis.qdCcateList.method,
        url: apis.qdCcateList.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            var d = res.data;
            indexHtml(d);
            $('#pageTotal').html(d.length);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}
//列表字符串
function indexHtml(d){
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<tr class="text-c">';
        h += '<td>' + d[i].cate_name + '</td>';
        h += '<td>' + d[i].uptime + '</td>';
        h += '<td class="f-14">';
        h += '<a href="javascript:;" onclick="card_edit(\'编辑\',\'card-cate-edit.html\', ' + d[i].id + ');" style="text-decoration: none">';
        h += '编辑<i class="Hui-iconfont">&#xe6df;</i>';
        h += '</a>';
        h += ' &nbsp; ';
        h += '<a href="javascript:;" onclick="card_del(' + d[i].id + ');" style="text-decoration: none; color: red;">';
        h += '删除<i class="Hui-iconfont">&#xe6e2;</i>';
        h += '</a>';
        h += '<input type="hidden" id="cname' + d[i].id + '" value="' + d[i].cate_name + '"/>';
        h += '</td>';
        h += '</tr>';
    }
    $('tbody').html(h);
}


//编辑
function card_edit(title,url,id,w,h){
    url += '?id=' + id;
    var cname = $('#cname' + id).val();
    cname = cname ? cname : '';
    url += '&cname=' + escape(cname);
    layer_show(title,url,w,500);
}


//更新
function modify(){
    var formData = {
        id: id,
        cname: $('#cname').val(),
    };
    console.log(formData);
    if (!formData.cname) {
        //layer.msg('SKU规格必须的',{icon: 0,time: 1000});
        msgPop({msg: '分类必须的'});
        return
    }
    //return
    $.ajax({
        type: apis.qdCcateModify.method,
        url: apis.qdCcateModify.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            msgPop({msg: '更新成功'});
            setTimeout(function(){
                top.location.reload();
            }, 1000);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}


//删除
function card_del(id){
    var msg = '确认要 <b style="color: red; font-size: 20px;">删除</b> 吗？';
    layer.confirm(msg,function(index){
        $.ajax({
            type: apis.qdCcateDel.method,
            url: apis.qdCcateDel.url,
            data: { id: id },
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    //msgPop({msg: res.msg});
                    layerMsgErr(res.msg);
                    return
                }
                //layer.msg('商品已删除!',{icon: 1,time: 1000});
                layerMsgOk('删除成功');
                setTimeout(function(){
                    top.location.reload();
                }, 1000);
            },
            error: function () {
                console.log('错误了！');
            }
        });
    });
}